/**
 * @author lk
 * @date 2022/6/1 19:53
 */
package com.mmall.spring5.aopanno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Date;

//增强类
@Component
@Aspect
@Order(1)
public class CupProxy {

    //前置通知
    @Before("addPointCut()")
    public void before() {
        System.out.println(String.valueOf(new Date()) + ", before advice ok!!!");
    }

    @After("addPointCut()")
    public void after() {
        System.out.println(String.valueOf(new Date()) + ", after advice ok!!!");
    }

    @AfterReturning("addPointCut()")
    public void afterReturning() {
        System.out.println(String.valueOf(new Date()) + ", afterReturning ok!!!");
    }

    @AfterThrowing("addPointCut()")
    public void afterThrowing() {
        System.out.println(String.valueOf(new Date()) + ", after throwing ok!!!");
    }

    @Around("addPointCut()")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println(getDate()+", before around...");
        proceedingJoinPoint.proceed();
        System.out.println(getDate()+", after around...");
    }

    @Pointcut("execution(* com.mmall.spring5.aopanno.Cup.add(..))")
    public void addPointCut() {
    }

    private String getDate() {
        return String.valueOf(new Date());
    }
}
